import Vue from 'vue'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
import App from './App.vue'
import store from './vuex/store'
import VueRouter from "vue-router"
import VueResource from "vue-resource"
//引入Element-UI进行app前端美化

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
//开启debug模式
Vue.config.debug = true;
Vue.use(VueRouter);
Vue.use(VueResource);
Vue.use(MintUI)
Vue.use(ElementUI)


import me from './components/me.vue'
import mineSetting from './components/mineSetting.vue'
import minepassage from './components/minepassage.vue'
import minecriteria from './components/minecriteria.vue'
import minejoin from './components/minejoin.vue'
import home from './components/home.vue'
import index from './components/index.vue'
import discovery from './components/discovery.vue'
import dynamic from './components/dynamic.vue'
import Detail from './components/Detail.vue'
import register from './components/register.vue'
import login from './components/login.vue'
import header from './components/header.vue'
import Boss from './components/Boss.vue'
import Boss_Message from './components/Boss_Message.vue'
import Boss_Detail from './components/Boss_Detail.vue'
import Boss_User from './components/Boss_User.vue'
import Boss_item from './components/Boss_item.vue'
import search from './components/search.vue'
import Addmessage from './components/Addmessage.vue'

// 创建一个路由器实例并且配置路由规则
const router = new VueRouter({
	mode: 'hash',
	base: __dirname,
	routes: [
		{
			path: '/',
			component: home,
			children: [
				{
					path: '',
					components: {
						index,
					  
						dynamic,
						me,
						discovery
					
					}
				}
			]
			
		
		},
		{
			path: '/item/:_id',
			name: 'detail',
			component: Detail
		},
		{
			path: '/Boss_item/:_id',
			name: 'Boss_item',
			component:Boss_item
		},
		{
      path: '/login',
      name: 'login',
      component: login
    },
	{
      path: '/register',
      name: 'register',
      component: register,

			
    },
	{
      path: '/Addmessage',
      name: 'Addmessage',
      component: Addmessage,

			
    },
	{
      path: '/mineSetting',
      name: 'mineSetting',
      component: mineSetting,

			
    },


	{
      path: '/minepassage',
      name: 'minepassage',
      component: minepassage,

			
    },

{
      path: '/minejoin',
      name: 'minejoin',
      component: minejoin,

			
    },
	{
      path: '/minecriteria',
      name: 'minecriteria',
      component: minecriteria,

			
    },
	{
      path: '/search',
      name: 'search',
      component: search,

			
    },
	{
      path: '/discovery',
      name: 'discovery',
      component: discovery,
	 beforeEnter:(to,from,next) =>{
        let usn=sessionStorage.getItem("username")
        if(usn!==null){
          next()
        }
        else{
          next({name:'login',
               query:{redirect: discovery}  
      })
		}
			}
    }
	,

	{
			path: '/Boss',
			component: Boss,
			children: [
				{
					path: '',
					components: {
						header
					}
				}
			],
	    beforeEnter:(to,from,next) =>{
        let usn=sessionStorage.getItem("username")
        if(usn!==null&&usn=="admin"){
          next()
        }
        else{
          next({name:'login',
               query:{redirect: discovery}  
      })
		}
			}
		},
	{
			path: '/Boss_Message',
			component: Boss_Message,
			children: [
				{
					path: '',
					components: {
						header
					}
				}
			]
		},
		{
			path: '/Boss_Detail',
			component: Boss_Detail,
			children: [
				{
					path: '',
					components: {
						header
					}
				}
			]
		},
		{
			path: '/Boss_User',
			component: Boss_User,
			children: [
				{
					path: '',
					components: {
						header
					}
				}
			]
		},
		
	]
})


//每次进入新组件后滚动条回到顶部
router.afterEach(function (to) {
	window.scrollTo(0, 0)
});

// 路由器会创建一个 App 实例，并且挂载到选择符 #app 匹配的元素上。
const app = new Vue({
	router: router,
	store,
	render: h => h(App)
}).$mount('#app')

